package com.lfs.adapter.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.lfs.adapter.config.ApplicationContextConfig;
import com.lfs.adapter.config.PlatformTypeConfig;
import com.lfs.adapter.dto.PddProductPropertyDto;
import com.lfs.adapter.service.PlatformManagerService;
import com.lfs.base.exception.BusinessException;
import com.lfs.interfaces.dto.LogisticsTemplateDto;
import com.lfs.interfaces.dto.TokenCreateDto;
import com.lfs.interfaces.model.vo.LogisticsTemplateVo;
import com.lfs.interfaces.model.vo.MallInfoVo;
import com.lfs.interfaces.model.vo.TokenCreateVo;
import com.pdd.pop.sdk.common.util.JsonUtil;
import com.pdd.pop.sdk.http.api.pop.request.PddGoodsAuthorizationCatsRequest;
import com.pdd.pop.sdk.http.api.pop.response.PddGoodsAuthorizationCatsResponse;
import com.pdd.pop.sdk.http.api.pop.response.PddGoodsCatsGetResponse;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class PlatformManagerServiceImpl implements PlatformManagerService {

    @Resource
    private PlatformTypeConfig platformTypeConfig;

    private PlatformManagerService getService(String platFormType) {
        platFormType=platformTypeConfig.getPlatformType(platFormType);
        try {
            return (PlatformManagerService) ApplicationContextConfig.getBean(platFormType.toLowerCase()+"PlatformManagerServiceImpl");
        }catch(NoSuchBeanDefinitionException e) {
            throw new BusinessException(500,"不支持的平台类型:"+platFormType);
        }
    }

    @Override
    public String getAuthUrl(TokenCreateDto tokenCreateDto) {
        PlatformManagerService service=getService(tokenCreateDto.getShopType());
        return service.getAuthUrl(tokenCreateDto);
    }

    @Override
    public TokenCreateVo getAccessToken(TokenCreateDto tokenCreateDto) {
        PlatformManagerService service=getService(tokenCreateDto.getShopType());
        return service.getAccessToken(tokenCreateDto);
    }

    @Override
    public String releaseProduct() {
        PlatformManagerService service = getService("pdd");
        return service.releaseProduct();
    }

    @Override
    public List<LogisticsTemplateVo> getLogisticsTemplate(LogisticsTemplateDto logisticsTemplateDto) {
        PlatformManagerService service = getService(logisticsTemplateDto.getShopType());
        return service.getLogisticsTemplate(logisticsTemplateDto);
    }

    @Override
    public MallInfoVo getMallInfo(TokenCreateDto tokenCreateDto) {
        PlatformManagerService service = getService(tokenCreateDto.getShopType());
        return service.getMallInfo(tokenCreateDto);
    }

    @Override
    public String getGoodsCats() {
        PlatformManagerService service = getService("pdd");
        return service.getGoodsCats();
    }

    @Override
    public String getGoodsRule() {
        PlatformManagerService service = getService("pdd");
        return service.getGoodsRule();
    }

    public String getCurrentCommodityCategory(String accessToken) {
        PlatformManagerService service = getService("pdd");
        return service.getCurrentCommodityCategory(accessToken);
    }


    public String searchPddBrand(String value, Long catId, Long refPid, String accessToken) {
        PlatformManagerService service = getService("pdd");
        return service.searchPddBrand(value, catId, refPid, accessToken);
    }

    public String getFreightTemplateData(String accessToken) {
        PlatformManagerService service = getService("pdd");
        return service.getFreightTemplateData(accessToken);
    }

    public String getVideoData(String accessToken) {
        PlatformManagerService service = getService("pdd");
        return service.getVideoData(accessToken);
    }

    public String getCurrentGoodsInfo(Long catId, String accessToken) {
        PlatformManagerService service = getService("pdd");
        return service.getCurrentGoodsInfo(catId, accessToken);
    }

    @Override
    public String getTwoPiecesDiscountRule(Long catId, String accessToken) {
        PlatformManagerService service = getService("pdd");
        return service.getTwoPiecesDiscountRule(catId, accessToken);
    }

    public String getGoodsSpecifications(Long catId, String accessToken) {
        PlatformManagerService service = getService("pdd");
        return service.getGoodsSpecifications(catId, accessToken);
    }

    public String getCustomSpecifications(Long parentSpecId, String specName, String accessToken) {
        PlatformManagerService service = getService("pdd");
        return service.getCustomSpecifications(parentSpecId, specName, accessToken);
    }

    public String getGoodsCountry(String accessToken) {
        PlatformManagerService service = getService("pdd");
        return service.getGoodsCountry(accessToken);
    }

    public String goodsImgUpload(String fileUrl, String accessToken) {
        PlatformManagerService service = getService("pdd");
        return service.goodsImgUpload(fileUrl, accessToken);
    }

    @Override
    public String filesPaceImgUpload(String fileUrl, String accessToken) {
        return null;
    }

    @Override
    public Map<String, Object> releaseGoods(PddProductPropertyDto pddProductPropertyDto, String accessToken) {
        PlatformManagerService service = getService("pdd");
        return service.releaseGoods(pddProductPropertyDto, accessToken);
    }

    @Override
    public String getPageCode(JSONObject jsonObject) {
        PlatformManagerService service = getService("pdd");
        return service.getPageCode(jsonObject);
    }
}
